#include "Sound.h"

// Initialize the sound singleton
Sound* Sound::m_SoundInstance = 0;

Sound* Sound::GetSoundInstance(void)
{
	// Create the singleton if it doesn't exist
	if(!m_SoundInstance)
		m_SoundInstance = new Sound;

	// Return the singleton
	return m_SoundInstance;
}

void Sound::DeleteInstance(void)
{
	// If instance exist, delete it!
	if(m_SoundInstance)
	{
		delete m_SoundInstance;
		m_SoundInstance = NULL;
	}
}

Sound::Sound(void)
{
}

Sound::~Sound(void)
{
}

void Sound::InitSounds(void)
{
	// Initialize the sound middleware
	FMOD::System_Create( &system );	// Create the main system object.

	system->init(100, FMOD_INIT_NORMAL, 0);	// Initialize FMOD

	// Create Game Music
	system->createStream("Audio/Music/lv1Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[1] );
	system->createStream("Audio/Music/lv2Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[2] );
	system->createStream("Audio/Music/lv3Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[3] );
	system->createStream("Audio/Music/lv4Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[4] );
	system->createStream("Audio/Music/lv5Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[5] );
	system->createStream("Audio/Music/lv6Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[6] );
	system->createStream("Audio/Music/lv2Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[7] );
	system->createStream("Audio/Music/lv3Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[8] );
	system->createStream("Audio/Music/lv4Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[9] );
	system->createStream("Audio/Music/lv5Music.mp3", FMOD_LOOP_NORMAL, 0, &levelMusic[10] );
	system->createStream("Audio/Music/menuMusic.mp3", FMOD_LOOP_NORMAL, 0, &menuScreenMusic );
	system->createStream("Audio/Music/miniGameMusic.mp3", FMOD_LOOP_NORMAL, 0, &miniGameMusic );

	// Create Collision Sound Effects
	system->createSound("Audio/SoundEffects/acidPitColSFX.mp3", FMOD_DEFAULT, 0, &collAcidPit );
	system->createSound("Audio/SoundEffects/matOrbColSFX.mp3", FMOD_DEFAULT, 0, &collMaterialOrb );
	system->createSound("Audio/SoundEffects/fireWallCollSFX.mp3", FMOD_DEFAULT, 0, &collFireWall );
	system->createSound("Audio/SoundEffects/teslaCoilCollSFX.mp3", FMOD_DEFAULT, 0, &collTeslaCoil );
	system->createSound("Audio/SoundEffects/pistonColSFX.mp3", FMOD_DEFAULT, 0, &collPiston );
	system->createSound("Audio/SoundEffects/circuitWallColSFX.mp3", FMOD_DEFAULT, 0, &collCircuitWall );
	system->createSound("Audio/SoundEffects/jumpPadColSFX.mp3", FMOD_DEFAULT, 0, &collJumpPad );

	// Create Input Sound Effects
	system->createSound("Audio/SoundEffects/menuBtnClkSFX.mp3", FMOD_DEFAULT, 0, &menuBtnClick );
	system->createSound("Audio/SoundEffects/pickFourBtnClk.mp3", FMOD_DEFAULT, 0, &pickFourBtnClk );
	system->createSound("Audio/SoundEffects/trackPlcCrtSFX.mp3", FMOD_DEFAULT, 0, &trackPlcCrt );
	system->createSound("Audio/SoundEffects/trackPlcIncSFX.mp3", FMOD_DEFAULT, 0, &trackPlcIncrt );
	system->createSound("Audio/SoundEffects/trackPlcCanSFX.mp3", FMOD_DEFAULT, 0, &trackPlcCan );
	system->createSound("Audio/SoundEffects/trackSlctSFX.mp3", FMOD_DEFAULT, 0, &trackSelected );
	system->createSound("Audio/SoundEffects/trackRotSFX.mp3", FMOD_DEFAULT, 0, &trackRotate );
	system->createSound("Audio/SoundEffects/cameraShiftSFX.mp3", FMOD_DEFAULT, 0, &cameraShift );
	system->createSound("Audio/SoundEffects/undoBtnClkSFX.mp3", FMOD_DEFAULT, 0, &undoBtnClk );
	system->createSound("Audio/SoundEffects/eightPieceSlctSFX.mp3", FMOD_DEFAULT, 0, &slideEightPceSlct );

	// Create Miscellaneous Sound Effects
	system->createSound("Audio/SoundEffects/voiceIntroSFX.mp3", FMOD_DEFAULT, 0, &voiceIntro );
}

// Music methods
void Sound::MenuScreenMusic()
{
	channel->stop();
	// Play the menu sound 
	system->playSound( FMOD_CHANNEL_FREE, menuScreenMusic, false, &channel );
}
void Sound::MiniGameMusic()
{
	channel->stop();
	// Play the menu sound 
	system->playSound( FMOD_CHANNEL_FREE, miniGameMusic, false, &channel );
}
void Sound::LevelMusic(int iCurrLevel)
{
	channel->stop();
	system->playSound( FMOD_CHANNEL_FREE, levelMusic[iCurrLevel], false, &channel );
}

// Collision SFX methods
void Sound::AcidPitCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collAcidPit, false, 0 );
}
void Sound::FireWallCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collFireWall, false, 0 );
}
void Sound::TeslaCoilCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collTeslaCoil, false, 0 );
}
void Sound::MaterialOrbCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collMaterialOrb, false, 0 );
}
void Sound::PistonCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collPiston, false, 0 );
}
void Sound::CircuitWallCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collCircuitWall, false, 0 );
}
void Sound::JumpPadCollisionSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, collJumpPad, false, 0 );
}

// Input SFX methods
void Sound::MenuButtonClickSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, menuBtnClick, false, 0 );
}
void Sound::PickFourButtonClickSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, pickFourBtnClk, false, 0 );
}
void Sound::TrackSelectedSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, trackSelected, false, 0 );
}
void Sound::TrackPlacedCorrectSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, trackPlcCrt, false, 0 );
}
void Sound::TrackPlacedIncorrectSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, trackPlcIncrt, false, 0 );
}
void Sound::TrackPlaceCancel()
{
	system->playSound( FMOD_CHANNEL_FREE, trackPlcCan, false, 0 );
}
void Sound::TrackRotateSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, trackRotate, false, 0 );
}
void Sound::CameraShiftSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, cameraShift, false, 0 );
}
void Sound::UndoButtonClickSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, undoBtnClk, false, 0 );
}
void Sound::SlideEightPieceSelectSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, slideEightPceSlct, false, 0 );
}
//Miscellaneous SFX methods
void Sound::IntroVoiceSFX()
{
	system->playSound( FMOD_CHANNEL_FREE, voiceIntro, false, 0 );
}

// Update Sound
void Sound::Update()
{
	system->update();
}